package com.srit.base.service.impl;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import com.srit.base.constant.BaseConstant;
import com.srit.base.service.EntityIdReflect;

public class EntityIntIdReflectImpl implements EntityIdReflect {

	@Override
	public Object reflectIdFromObject(Object object)
			throws NoSuchFieldException, SecurityException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
		Class clz = object.getClass();
		Field field = clz.getDeclaredField(BaseConstant.ENTITY_ID_FIELD);
		String getName = BaseConstant.ENTITY_GET_METHOD
				+ field.getName().substring(0, 1).toUpperCase()
				+ field.getName().substring(1);
		Method getMethod = clz.getMethod(getName, new Class[] {});
		Object idValue = getMethod.invoke(object, new Object[] {});
		return idValue;
	}

}
